//
//  BaseTableViewController.swift
//  RuiLinWeibo
//
//  Created by Caesar on 15/10/8.
//  Copyright © 2015年 Caesar. All rights reserved.
//
// 建一个基类, 让所有的 tabalViewcontrllor 继承它, 以增加新的功能

import UIKit

class BaseTableViewController: UITableViewController, VistorLoginViewDelegate {
    // 用户登录标记
    var userLogon = UserAccount.userLogon   //UserAccount.loadAccount() != nil
    
    // 访客视图
    var visitorView: VistorLoginView?
    
    override func loadView() {
        // 更具用户是否登录,判断是否更换根视图
        userLogon ? super.loadView() : setupVistorView()
    }
    
    // 设置访客视图
    private func setupVistorView(){
        visitorView = VistorLoginView()
        visitorView?.delegate = self
        view = visitorView
        
    //设置状态栏
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorLoginViewWillRegister")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorLoginViewWillLogin")
    }
    
    // MARK: - VistorLoginViewDelegate
    func vistorLoginViewWillLogin() {
        let nav = UINavigationController(rootViewController: OAuthViewController())
        
        presentViewController(nav, animated: true, completion: nil)
    }
    func vistorLoginViewWillRegister() {
        print("注册")
    }
    
    
}